package io.gitee.mojingjiao.day02;

import org.junit.Test;

import java.util.Scanner;

public class TaskTwo{


//计算一元二次方程

    public static void gen(double a,double b,double c){
        double i;
        double j = 1.0;
        double k = 1.0;
        i = b * b - 4 * a * c;
        if (i >= 0) {
            j = ((-b) + Math.sqrt(i)) / 2 * a;
            k = (b + Math.sqrt(i)) / 2 * a;
        }
        System.out.println("j:" + j);
        System.out.println("k:" + k);
    }
//        public static void main (String[] args){
//            Scanner sc=new Scanner(System.in);
//            double a = sc.nextDouble();
//            double b = sc.nextDouble();
//            double c = sc.nextDouble();
//            gen(a,b,c);


//        }




//        求最大公约数

    public static void gcd(int m,int n){
     while(true){
         if((m=m%n)==0)
             System.out.println(n);
         if((n=n%m)==0)
             System.out.println(m);
     }
    }
//    public static void main(String[] args) {
//        Scanner gc= new Scanner (System.in);
//        int m=gc.nextInt();
//        int n=gc.nextInt();
//        gcd(m,n);
//    }



//计算素数

//输入一个数，最终打印是否为素数
public static void pri(int n) {
        int a=2;
        int flag=0;
        while(a<n) {
            if (n % a == 0) {
                System.out.println("不是素数");
                flag = 1;
              break;
            }
            a++;
        }
        if(flag==0){
                System.out.println("是素数");
            }
        }
//    public static void main(String[] args) {
//      Scanner num=new Scanner(System.in);
//      int n=num.nextInt();
//      pri(n);
//
//}



//        打印100以内的所有素数
@Test
public void textPrime(){

      for(int i=2;i<=100;i++){
          int flag=0;
          int n=2;
          while(n<i){
             if(i%n==0){
                 flag=1;
                 break;
//                 跳出当前的while循环，执行n++
             }
             n++;
          }
          if (flag==0){
              System.out.print(i+" ");
          }
      }
}


//使用坐标法打印形状
@Test
    public void testShape1() {
        for (int j = -2; j <= 2; j++) {
            for (int i = -2; i <= 2; i++) {
                if(i==j||i==-j||j==-i)
                { System.out.print("* ");}
                else{
                    System.out.print(".");
                }

            }

            System.out.println();
        }

    }


    @Test
    public void testShape2(){
        for (int j = -2; j <= 2; j++){
            for (int i = -2; i <= 2; i++){
                if(Math.abs(j)+Math.abs(i)==2||Math.abs(j)+Math.abs(i)==1||Math.abs(j)+Math.abs(i)==0){
                    System.out.print("*");
                }else{
                    System.out.print(".");
                }
            }
            System.out.println();
        }
    }
@Test
    public void textShape3() {
        for (int j = -2; j <= 2; j++){
            for (int i = -2; i <= 2; i++){
                if(i==j||i==-j||j==-i||Math.abs(i)>Math.abs(j)){
                    System.out.print("*");
                }else{
                    System.out.print(".");
                }
            }
            System.out.println();
        }
    }







}
